package com.momo.elasticsearch.entity;

import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

import java.util.Map;

/**
 * Created by MOMO on 2019/3/11.
 */
@Slf4j
public class ElasticsearchDataType {
    /**
     *
     * @param type 字段类型
     * @param index 不需要被搜索设置成false 控制当前字段是否是索引,默认为true
     * @param indexOptions #index_ptions 用于控制倒排索引记录的内容
                            -docs 只记录docid
                            -freqs记录docid和term frequencies
                            -positions 记录dcid、term frequencies和term position
                            -offsets 记录docid 、term frequencies、term position和character offset
                            text 类型默认配置为positions，其他默认为docs
                            记录内容越多，占用空间越大
     * @return
     */
    public static Map<String, String> getType(String type,String index,String indexOptions) {
        Map<String, String> map = Maps.newConcurrentMap();
        map.put("type", type);
        if (StringUtils.isNotEmpty(index)){
            map.put("index", index);
        }
        if (StringUtils.isNotEmpty(indexOptions)){
            map.put("index", index);
        }
        return map;
    }

    //存储数据的时候，会自动分词，并生成索引
    public static String TEXT = "text";
    //存储数据的时候，不会分词，而是直接整个词拿去建索引
    public static String KEYWORD = "keyword";
    public static String BYTE = "byte";
    public static String SHORT = "short";
    public static String INTEGER = "integer";
    public static String LONG = "long";
    public static String FLOAT = "float";
    public static String DOUBLE = "double";
    public static String BOOLEAN = "boolean";
    public static String DATE = "date";
}
